﻿using Log.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Navigation.Regions;
using System;
using System.Windows;

namespace Log
{
    public class LogModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {        
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            try
            {
                #region             
                //注意此处使用反射的方法降低了程序的耦合度,Log项目并未引用CSVData项目，Log项目只引用了Core项目
                //此处依赖的是抽象ICSVDataHelper 而不是CSVDataHelper              
                #endregion

                #region 使用反射的方法获取程序集的Type然后注册
                //string dllFilePath = this.GetType().Assembly.Location;//获取当前程序集的路径
                //Assembly assembly = Assembly.LoadFrom(Path.GetDirectoryName(dllFilePath) + "\\CSVData.dll");
                //Type type = assembly.GetType("CSVData.Class.CSVDataHelper");
                //containerRegistry.Register(typeof(ICSVDataHelper), type);
                #endregion

                #region
                //containerRegistry.Register(typeof(ICSVDataHelper), () =>
                //{
                //    string dllFilePath = this.GetType().Assembly.Location;//获取当前程序集的路径
                //    Assembly assembly = Assembly.LoadFrom(Path.GetDirectoryName(dllFilePath) + "\\CSVData.dll");
                //    Type type = assembly.GetType("CSVData.CSVDataHelper"); //
                //    if (type != null)
                //    {
                //        return Activator.CreateInstance(type);
                //    }
                //    else
                //    {
                //        MessageBox.Show("无法找到程序集!"+ "CSVData.dll");
                //        return null;
                //    }
                //});

                //containerRegistry.RegisterSingleton(typeof(INotifyCollect), typeof(NotifyCollect));
                #endregion


                //注册导航
                containerRegistry.RegisterForNavigation<MessageView>();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
